home
***
CD-ROM
|
disk
|
FTP
|
other
***
search
/
Night Owl 9
/
Night Owl CD-ROM (NOPV9) (Night Owl Publisher) (1993).ISO
/
038a
/
satsfaxt.zip
/
CCPUTILS.EXE
/
CCSTAT.C
< prev
next >
Wrap
Text File
|
1990-01-30
|
45KB
|
884 lines
/*---------------------------------------------------------------------------*
* CCSTAT.C *
*---------------------------------------------------------------------------*
* The program allows the user to view the contents of the receive/send/log *
* queues as defined in the DCA/Intel CAS 1.0A specification. Additionally, *
* the hardware status can be viewed and on-board diagnostics can be *
* run. All options, filenames and addresses are specified on the *
* command line. *
* *
* The following source code is intended to assist developers in *
* creating applications which support the DCA/Intel Communicating *
* Applications Specification Version 1.0A. It is provided free of charge *
* and on an as-is basis. THE IMPLIED WARRANTIES OF MERCHANTABILITY AND *
* FITNESS FOR A PARTICULAR PURPOSE ARE SPECIFICALLY EXCLUDED. This source *
* code may be modified, enhanced, copied and distributed with applications *
* that support CAS on a royalty free basis. *
*---------------------------------------------------------------------------*/
#include <stdio.h>
#include <dos.h>
#include <io.h>
#include <malloc.h>
#include <string.h>
#include "cas.h" /* Intel CAS header file. */
#include "parse.h" /* Command line parser header file. */
#include "util.h" /* CAS utilities header file. */
#define UpperBound(a) (sizeof(a)/sizeof(a[0]))
int Diagnostics = FALSE; /* Run diagnostics if TRUE. */
int HardwareOnly = FALSE; /* Show only the status of hardware if TRUE. */
char *JobNo = "0"; /* Show status of single job. */
unsigned long EventNo = 0L; /* Converted job number. */
int TransmitOnly = FALSE; /* Show Task Queue if TRUE. */
int LogOnly = FALSE; /* Show Log Queue if TRUE. */
int ShowAll = FALSE; /* Show Task & Log Queues if TRUE. */
int CurrentEvent = FALSE; /* Show Current Event if TRUE. */
int ARState = FALSE; /* Show autoreceive state. */
int AnswerOnRing = -1; /* Set autoreceive state. */
int Help = FALSE; /* Show help text. */
int NewOnly = FALSE; /* Show only new tasks. */
int RedirOut = FALSE; /* Redirect output to file. */
CECS *TSTATbuffer; /* Task status buffer. */
ECF *TCFbuffer; /* Task Control File buffer. */
FTR *FTRbuffer; /* File Transfer Record buffer. */
EDB *EDBbuffer; /* External Data Block buffer. */
FILE *ccout; /* Redirected stdout file. */
int FileHandle; /* File handle of Task Control File. */
/* CAS errors (exit code field is the CAS error number). */
ERRORMSG CASEmsg[] = {
{ 0x0000, "" },
{ 0x0002, "Image file is corrupted" },
{ 0x0003, "File was sent, but it might contain errors" },
{ 0x0004, "Receive data lost" },
{ 0x0005, "Invalid or missing logofile" },
{ 0x0006, "File name doesn't match NSF header" },
{ 0x0007, "File size doesn't match NSF header" },
{ 0x0200, "Internal error. Task switch failed" },
{ 0x0201, "Unknown command" },
{ 0x0202, "Event not found" },
{ 0x0203, "Tried to findnext with previous findfirst" },
{ 0x0204, "No more events" },
{ 0x0207, "Unknown schedule division" },
{ 0x0208, "Bad event control file" },
{ 0x0209, "Connection CoProcessor is busy" },
{ 0x020A, "Invalid PCAM parameter" },
{ 0x020B, "Can't uninstall PCAM" },
{ 0x020C, "File already exists" },
{ 0X0280, "Unknown task type" },
{ 0X0281, "Bad phone number" },
{ 0X0282, "Bad .PCX file header" },
{ 0X0283, "Unexpected end of file" },
{ 0X0284, "Phone line disconnected during event" },
{ 0X0286, "No files specified to send" },
{ 0X0287, "Connection CoProcessor isn't responding" },
{ 0X0288, "More than 1023 pages of receive data" },
{ 0X0289, "Manual connect posted too long ago" },
{ 0X028A, "Connection CoProcessor command set error" },
{ 0X028B, "Bad NSF header file" },
{ 0X0401, "Remote unit not Group 3 compatible" },
{ 0X0402, "Remote unit didn't send its capabilities" },
{ 0X0403, "Remote unit requested disconnect" },
{ 0X0404, "Remote unit isn't a CCP" },
{ 0X0405, "Exceeded retrain or fax resend limit" },
{ 0X0406, "Line noise or CCP & remote don't agree on bit rate" },
{ 0X0407, "Remote unit disconnected after receiving data" },
{ 0X0408, "No reply from remote unit after sending data" },
{ 0X0409, "Capabilities of remote unit aren't compatible" },
{ 0X040B, "Invalid reply from remote unit after sending data" },
{ 0X040D, "Phone line dead or remote unit disconnected" },
{ 0X0411, "Invalid command from remote after receiving data" },
{ 0X0415, "Tried to receive from incompatible hardware" },
{ 0X041F, "Unexpected end of file while receiving" },
{ 0X045D, "Remote unit unexpectedly stopped sending data" },
{ 0X045E, "Remote unit didn't send any data" },
{ 0X045F, "Remote unit took too long to send fax scan line" },
{ 0X0463, "Can't get through to remote unit" },
{ 0X0464, "User canceled event" }
};
/* Argument table for command line processor. */
STABLE SwitchTable[] = /* Command line parser switch table. */
{
{ 'A', BOOL, &ARState },
{ 'a', BOOL, &ARState },
{ 'S', INT, &AnswerOnRing },
{ 's', INT, &AnswerOnRing },
{ 'D', BOOL, &Diagnostics },
{ 'd', BOOL, &Diagnostics },
{ 'H', BOOL, &HardwareOnly },
{ 'h', BOOL, &HardwareOnly },
{ 'E', STRING, (int *)&JobNo },
{ 'e', STRING, (int *)&JobNo },
{ 'L', BOOL, &LogOnly },
{ 'l', BOOL, &LogOnly },
{ 'P', BOOL, &TransmitOnly },
{ 'p', BOOL, &TransmitOnly },
{ 'N', BOOL, &NewOnly },
{ 'n', BOOL, &NewOnly },
{ 'C', BOOL, &CurrentEvent },
{ 'c', BOOL, &CurrentEvent },
{ 'R', BOOL, &RedirOut },
{ 'r', BOOL, &RedirOut },
{ '?', BOOL, &Help }
};
#define TABLESIZE (sizeof(SwitchTable)/sizeof(STABLE))
char *DescTable[] = /* Help function description table. */
{
"CCSTAT (V1.0) View contents of the send, receive, and log queues.\n\n",
"By specifying the appropriate options, you can view the hardware status and \n",
"run on-board diagnostics.\n\n",
"Syntax: CCSTAT [option...]\n\n"
};
#define DESCSIZE (sizeof(DescTable)/sizeof(DescTable[0]))
char *HelpTable[] = /* Help function switch table. */
{
" /A Display answer mode (# of rings before answer).\n",
" /S<number> Set answer mode.\n\n",
" /E<number> Display status of the event specified by number.\n\n",
" /C Display information about the current event.\n",
" /N Display only new events.\n",
" /L Display information about logged (completed) events.\n",
" /P Display information about pending events.\n",
" /D Run Connection CoProcessor diagnostics.\n",
" /H Display information about hardware status.\n\n",
" /R Redirect output to file OUTPUT.CC.\n",
" /? Display help information.\n"
};
#define HELPSIZE (sizeof(HelpTable)/sizeof(HelpTable[0]))
/*---------------------------------------------------------------------------*
* RunDiagnostics() *
*---------------------------------------------------------------------------*
* This function runs on-board diagnostics. It will not return until the *
* hardware has finished with the diagnostics routines. The status (Pass *
* or Fail) is displayed as appropriate. *
*---------------------------------------------------------------------------*
* Parameters: none *
* Return: none *
*---------------------------------------------------------------------------*/
int RunDiagnostics()
{
int result; /* Return value from CASRunDiagnostics. */
/* Start the diagnostics routine running. */
if((result = CASRunDiagnostics(START)) == SUCCESS)
fprintf(stdout, " Diagnostics started ");
else
CASError(CASDIAG, TRUE, -result);
/* Check the status. This function returns only when diags are complete. */
while ((result = CASRunDiagnostics(STATUS)) == 0x40);
if (result == SUCCESS)
fprintf(stdout, "\r Diagnostics completed successfully. \n");
else
CASError(CASHW, TRUE, -result);
}
/*---------------------------------------------------------------------------*
* ShowHWStatus() *
*---------------------------------------------------------------------------*
* Shows the current status of the Connection CoProcessor hardware. The *
* current status can be determined by checking the status of the current *
* event. Note that if there is no current event, CASGetTaskStatus *
* has error code "-NO_MORE_EVENTS". This is not really an error- rather just*
* the fact that there is no current event on the board. *
*---------------------------------------------------------------------------*
* Parameters: CECS *TSTATbuffer - Uninitialized CECS structure, filled *
* with Task Control information about the current event. *
* EDB *EDBbuffer - Uninitialized EDB buffer, filled with *
* External Data Block on return. *
* Return: none *
*---------------------------------------------------------------------------*/
ShowHWStatus(CECS *TSTATbuffer, EDB *EDBbuffer)
{
int state; /* State of hardware. */
int EventHandle; /* Current event handle. */
char msg[35]; /* Output message. */
/* Fill the TSTATbuffer with information about the current event. */
if((EventHandle = CASGetCurrentEventStatus(TSTATbuffer)) > 0)
state = TSTATbuffer->ControlFile.EventStatus;
else
state = EventHandle; /* contains error code */
switch (state) {
case -NO_MORE_EVENTS : /* Note: this is really an error value! */
case COMPLETED : strcpy(msg, "Connection CoProcessor idle."); break;
case WAITING : strcpy(msg, "Connection CoProcessor waiting."); break;
case DIALED : strcpy(msg, "Connection CoProcessor dialing."); break;
case SENDING : strcpy(msg, "Connection CoProcessor sending."); break;
case RECEIVING : strcpy(msg, "Connection CoProcessor receiving."); break;
case ABORTED : strcpy(msg, "Connection CoProcessor aborted."); break;
}
fprintf(stdout, "%s\n", msg);
}
/*---------------------------------------------------------------------------*
* GetTaskBuffer() *
*---------------------------------------------------------------------------*
* Opens the task control file and fill a TCFbuffer with the task control *
* information. The handle returned by the CAS function call is a normal *
* MS-DOS file handle. *
*---------------------------------------------------------------------------*
* Parameters: int Handle - Event handle to open. *
* BYTE Queue - Queue (Task, Receive or Log) to search. *
* char *TCFbuffer - Uninitialized ECS structure, filled with *
* Task Control info on return. *
* int *FileHandle - Filled with DOS file handle on return. *
* Return: none *
*---------------------------------------------------------------------------*/
GetTaskBuffer(int Handle, BYTE Queue, char *TCFbuffer, int *FileHandle)
{
/* Let CAS open the file and return the MS-DOS file handle. */
if((*FileHandle = CASOpenFile(Handle,0,Queue)) > 0) {
read(*FileHandle, TCFbuffer, sizeof(ECF));
}
else
CASError(CASNOTCF, TRUE, -(*FileHandle));
}
/*---------------------------------------------------------------------------*
* GetFileTransferBuffer() *
*---------------------------------------------------------------------------*
* Reads a single file transfer buffer. Normally, if the file does not *
* contain cover page text this record will begin at offset 383 of the *
* control file. If there is cover page text, then you can find the offset *
* of the first FTR record at offset 10 in the control file. In either *
* case, each additional FTR record is located 128 bytes past the start of *
* the previous FTR. *
*---------------------------------------------------------------------------*
* Parameters: lonf Offset - File offset to begin reading at. *
* char *FTRbuffer - Uninitialized FTR structure, filled with *
* File Transfer info on return. *
* int *FileHandle - DOS file handle obtained from a call to *
* CASOpenFile(). *
* Return: none *
*---------------------------------------------------------------------------*/
GetFileTransferBuffer(long Offset, char *FTRbuffer, int *FileHandle)
{
lseek(*FileHandle, Offset, SEEK_SET);
read(*FileHandle, FTRbuffer, sizeof(FTR));
}
/*---------------------------------------------------------------------------*
* CorrectDate() *
*---------------------------------------------------------------------------*
* Converts a date as stored in a control file to a string that can be *
* displayed on stdout. The TCFbuffer must first be read from the control *
* file. *
*---------------------------------------------------------------------------*
* Parameters: ECF *TCFbuffer - Filled in ECS structure. *
* char string[] - Array to place ascii date string. *
* Return: none *
*---------------------------------------------------------------------------*/
CorrectDate(ECF *TCFbuffer, char string[])
{
int day, month, year; /* Vars to hold date values. */
int minute, hour; /* Vars to hold time values. */
day = TCFbuffer->EventDate & 0x001F;
month = (TCFbuffer->EventDate & 0x01E0) >> 5;
year = ((TCFbuffer->EventDate & 0xFE00) >> 9) + 1980;
minute = (TCFbuffer->EventTime & 0x07E0) >> 5;
hour = (TCFbuffer->EventTime & 0xF800) >> 11;
sprintf(string, "%02d/%02d/%02d %02d:%02d", month, day, year, hour, minute);
}
/*---------------------------------------------------------------------------*
* ShowEventStatus() *
*---------------------------------------------------------------------------*
* Shows the status of the indicated queue. Jobs are shown in *
* chronological order. *
*---------------------------------------------------------------------------*
* Parameters: int Status - Type (status) of events to search for. *
* BYTE Queue - What queue to search (Task, Receive, Log). *
* ECF *TCFbuffer - Uninitialized ECF structure. *
* FTR *FTRbuffer - Uninitialized FTR structure. *
* Return: none *
*---------------------------------------------------------------------------*/
ShowQueueStatus(int Status, BYTE Queue, ECF *TCFbuffer, FTR *FTRbuffer)
{
int EventHandle; /* Event handle. */
int Offset; /* FTR offset. */
int Count; /* File count. */
int NewEvents = 0; /* # of new events in queue. */
int ShowIt = TRUE; /* New events flag. */
char Date[20]; /* Date string. */
char EventStatus[10]; /* Event status string. */
char Action[8]; /* Event type. */
char TransType[5]; /* Transfer type string. */
/* Find the first entry in the indicated queue. Call this function the
first time. Thereafter, call CASFindNext. */
if((EventHandle = CASFindFirst(Status,SEARCH_FORWARD,Queue)) > 0) {
/* Get information about the event found above. Don't forget to close
* the file! */
GetTaskBuffer(EventHandle, Queue, (char *)TCFbuffer, &FileHandle);
if(NewOnly) {
if((TCFbuffer->EventType == RECEIVE) || (TCFbuffer->EventType == POLLED_RECEIVE)) {
Offset = TCFbuffer->FTROffset;
for(Count = 1; Count <= TCFbuffer->FileCount; Count++) {
/* Get information about the transferred files. */
GetFileTransferBuffer((long)Offset, (char *)FTRbuffer, &FileHandle);
Offset = Offset + 128;
if(FTRbuffer->FileStatus != UNTOUCHED)
ShowIt = FALSE;
}
}
else
/* Don't show sends or polled sends! */
ShowIt = FALSE;
}
close(FileHandle);
if(ShowIt) {
++NewEvents;
CorrectDate(TCFbuffer, Date);
switch(TCFbuffer->TransferType) {
case FAX_200 : strcpy(TransType, "Fine"); break;
case FAX_100 : strcpy(TransType, "Std "); break;
case FILE_TRANSFER : strcpy(TransType, "CCP "); break;
default : strcpy(TransType, " "); break;
}
switch(TCFbuffer->EventStatus) {
case COMPLETED : strcpy(EventStatus, "Completed"); break;
case WAITING : strcpy(EventStatus, "Waiting "); break;
case DIALED : strcpy(EventStatus, "Dialed "); break;
case SENDING : strcpy(EventStatus, "Sending "); break;
case RECEIVING : strcpy(EventStatus, "Receiving"); break;
case ABORTED : strcpy(EventStatus, "Aborted "); break;
default : strcpy(EventStatus, "Error "); break;
}
switch(TCFbuffer->EventType) {
case SEND : strcpy(Action, "Send"); break;
case RECEIVE : strcpy(Action, "Recv"); break;
case POLLED_SEND : strcpy(Action, "Send(P)"); break;
case POLLED_RECEIVE : strcpy(Action, "Recv(P)"); break;
default : strcpy(Action, "Error"); break;
}
/* Display information. */
fprintf(stdout, "\n%6d %14s %-8s %4s %9s %-6s%-24s",
EventHandle,
Date,
Action,
TransType,
EventStatus,
TCFbuffer->EventType ? "From:":" To:",
TCFbuffer->EventType ? TCFbuffer->SenderName : TCFbuffer->DestinationName);
}
/* Find the remaining entries in the indicated queue. The parametes
* for status and direction are used from the last call to
* CASFindFirst. */
while((EventHandle = CASFindNext(Queue)) > 0) {
ShowIt = TRUE;
/* Again, read the information and display it. */
GetTaskBuffer(EventHandle, Queue, (char *)TCFbuffer, &FileHandle);
if(NewOnly) {
if((TCFbuffer->EventType == RECEIVE) || (TCFbuffer->EventType == POLLED_RECEIVE)) {
Offset = TCFbuffer->FTROffset;
for(Count = 1; Count <= TCFbuffer->FileCount; Count++) {
/* Get information about the transferred files. */
GetFileTransferBuffer((long)Offset, (char *)FTRbuffer, &FileHandle);
Offset = Offset + 128;
if(FTRbuffer->FileStatus != UNTOUCHED)
ShowIt = FALSE;
}
}
else
/* Don't show sends or polled sends. */
ShowIt = FALSE;
}
close(FileHandle);
if(ShowIt) {
++NewEvents;
CorrectDate(TCFbuffer, Date);
switch(TCFbuffer->TransferType) {
case FAX_200 : strcpy(TransType, "Fine"); break;
case FAX_100 : strcpy(TransType, "Std "); break;
case FILE_TRANSFER : strcpy(TransType, "CCP "); break;
default : strcpy(TransType, " "); break;
}
switch(TCFbuffer->EventStatus) {
case COMPLETED : strcpy(EventStatus, "Completed"); break;
case WAITING : strcpy(EventStatus, "Waiting "); break;
case DIALED : strcpy(EventStatus, "Dialed "); break;
case SENDING : strcpy(EventStatus, "Sending "); break;
case RECEIVING : strcpy(EventStatus, "Receiving"); break;
case ABORTED : strcpy(EventStatus, "Aborted "); break;
default : strcpy(EventStatus, "Error "); break;
}
switch(TCFbuffer->EventType) {
case SEND : strcpy(Action, "Send"); break;
case RECEIVE : strcpy(Action, "Recv"); break;
case POLLED_SEND : strcpy(Action, "Send(P)"); break;
case POLLED_RECEIVE : strcpy(Action, "Recv(P)"); break;
default : strcpy(Action, "Error"); break;
}
fprintf(stdout, "\n%6d %14s %-8s %4s %9s %-6s%-24s",
EventHandle,
Date,
Action,
TransType,
EventStatus,
TCFbuffer->EventType ? "From:":" To:",
TCFbuffer->EventType ? TCFbuffer->SenderName : TCFbuffer->DestinationName);
}
}
if(NewEvents == 0)
fprintf(stdout, "None\n");
fprintf(stdout, "\n");
}
/* If a call to CASFindFirst returns an error 204h, the queue is empty. */
else if(-EventHandle == 0x204)
fprintf(stdout, "None\n");
else
if(EventHandle < 0)
CASError(CASHW, TRUE, -EventHandle);
}
/*---------------------------------------------------------------------------*
* FindEvent() *
*---------------------------------------------------------------------------*
* Finds whic queue the specified job resides in. Searches the log queue *
* first and then the task queue. Returns the queue number. *
*---------------------------------------------------------------------------*
* Parameters: int EventHandle - Event handle to find. *
* Return: The queue in which the specified event is located in. *
*---------------------------------------------------------------------------*/
FindEvent(int EventHandle)
{
int JobNo = 0; /* Comparison job number. */
/* Search the Log Queue. */
JobNo = CASFindFirst(ANY_STATUS,SEARCH_FORWARD,LOG_QUEUE);
if(JobNo == EventHandle)
return(LOG_QUEUE);
else {
while((JobNo = CASFindNext(LOG_QUEUE)) > 0) {
if(JobNo == EventHandle)
return(LOG_QUEUE);
}
}
/* Search the Task Queue. */
JobNo = CASFindFirst(ANY_STATUS,SEARCH_FORWARD,TASK_QUEUE);
if(JobNo == EventHandle)
return(TASK_QUEUE);
else {
while((JobNo = CASFindNext(TASK_QUEUE)) > 0) {
if(JobNo == EventHandle)
return(TASK_QUEUE);
}
}
/* Event wasn't found - oops! */
return(-1);
}
/*---------------------------------------------------------------------------*
* ShowJobStatus() *
*---------------------------------------------------------------------------*
* Shows the status of an individual job. The information is retrieved *
* from the file transfer records that are part of the control file. *
*---------------------------------------------------------------------------*
* Parameters: int EventHandle - Handle of event to show status for. *
* ECF *TCFbuffer - Uninitialized ECF structure, filled in with *
* Task Control info on return. *
* FTR *FTRbuffer - Uninitialized FTR structure. *
* Return: none *
*---------------------------------------------------------------------------*/
ShowJobStatus(int EventHandle, ECF *TCFbuffer, FTR *FTRbuffer, CECS *Current)
{
char Date[20]; /* Date string. */
char msg[30]; /* Output message. */
long Offset; /* FTR offset. */
int x; /* For loop variable. */
BYTE Queue; /* Queue to search. */
int len; /* String length. */
int CurrentEvent; /* Current event handle. */
/* If user is trying to get status on current event, call ShowCurrent-
EventStatus(). */
if((CurrentEvent = CASGetCurrentEventStatus(Current)) == EventHandle) {
ShowCurrentEvent(Current);
return;
}
/* Have to find the correct queue first. */
Queue = FindEvent(EventHandle);
/* Get information about the task. */
GetTaskBuffer(EventHandle, Queue, (char *)TCFbuffer, &FileHandle);
CorrectDate(TCFbuffer, Date);
fprintf(stdout, "EVENT NUMBER : %lu\n", EventNo);
fprintf(stdout, "FROM : %s\n", TCFbuffer->SenderName);
fprintf(stdout, "TO : %s\n\n", TCFbuffer->DestinationName);
switch(TCFbuffer->EventStatus) {
case COMPLETED : strcpy(msg, "Successfully completed"); break;
case WAITING : strcpy(msg, "Waiting to be processed"); break;
case DIALED : strcpy(msg, "Number has been dialed"); break;
case SENDING : strcpy(msg, "Connection made -- sending"); break;
case RECEIVING : strcpy(msg, "Connection made -- receiving"); break;
case ABORTED : strcpy(msg, "Event was aborted"); break;
default : {
strcpy(msg, "CCAM Error : ");
for(x = 1; x < UpperBound(CASEmsg); x++) {
if(CASEmsg[x].ExitCode == -TCFbuffer->EventStatus) {
strcat(msg, CASEmsg[x].Message);
break;
}
}
}
}
fprintf(stdout, "EVENT STATUS : %s\n", msg);
fprintf(stdout, "ERRORS : %d\n", TCFbuffer->ErrorCount);
switch(TCFbuffer->EventType) {
case SEND : strcpy(msg, "Send"); break;
case RECEIVE : strcpy(msg, "Receive"); break;
case POLLED_SEND : strcpy(msg, "Polled Send"); break;
case POLLED_RECEIVE : strcpy(msg, "Polled Receive"); break;
default : strcpy(msg, "Error"); break;
}
fprintf(stdout, "EVENT TYPE : %s\n", msg);
switch(TCFbuffer->TransferType) {
case FAX_200 : strcpy(msg, "200x200 Fax"); break;
case FAX_100 : strcpy(msg, "100x200 Fax"); break;
case FILE_TRANSFER : strcpy(msg, "File Transfer"); break;
default : strcpy(msg, " "); break;
}
fprintf(stdout, "TRANSFER TYPE : %s\n", msg);
fprintf(stdout, "DATE : %s\n", Date);
fprintf(stdout, "CONNECT TIME : %02d hr %02d min %02d sec\n",
(int)TCFbuffer->ConnectHours,
(int)TCFbuffer->ConnectMinutes,
(int)TCFbuffer->ConnectSeconds);
fprintf(stdout, "NUMBER OF FILES : %d\n", TCFbuffer->FileCount);
fprintf(stdout, "COVER PAGE : %s\n\n", TCFbuffer->SendCover ? "Yes":"No");
if(TCFbuffer->FileCount > 0) {
fprintf(stdout, "FILE FILE STATUS SIZE/PAGES NAME\n");
Offset = TCFbuffer->FTROffset;
/* Get information about the transferred files. */
GetFileTransferBuffer(Offset, (char *)FTRbuffer, &FileHandle);
for(x = 1; x <= TCFbuffer->FileCount; x++) {
fprintf(stdout, "%3d", x);
switch(FTRbuffer->FileStatus) {
case UNTOUCHED : strcpy(msg, "Untouched"); break;
case OPENED : strcpy(msg, "Opened"); break;
case MOVED : strcpy(msg, "Saved"); break;
case DELETED : strcpy(msg, "Deleted"); break;
case NOT_RECEIVED : strcpy(msg, "Not Received"); break;
}
fprintf(stdout, " %-15s", msg);
switch(TCFbuffer->TransferType) {
case FAX_200 :
case FAX_100 : fprintf(stdout, " %6d", FTRbuffer->PageCount);
break;
case FILE_TRANSFER: fprintf(stdout, "%6ld ", FTRbuffer->FileSize);
break;
}
if((len = strlen(FTRbuffer->FileName)) > 40)
fprintf(stdout, " ...%-40s\n", FTRbuffer->FileName[80 - len]);
else
fprintf(stdout, " %-40s\n", FTRbuffer->FileName);
/* Next FTR is always 128 bytes after the previous one. */
Offset = Offset + 128;
GetFileTransferBuffer(Offset, (char *)FTRbuffer, &FileHandle);
}
/* Close the Control File. */
close(FileHandle);
}
}
/*---------------------------------------------------------------------------*
* ShowCurrentEvent() *
*---------------------------------------------------------------------------*
* Displays status information for the currently executing event. The *
* information is retrieved using the CASGetCurrentEventStatus call. *
*---------------------------------------------------------------------------*
* Parameters: CECS *Current - Uninitialized CECS structure, filled with *
* current event info on return. *
* Return: none *
*---------------------------------------------------------------------------*/
ShowCurrentEvent(CECS *Current)
{
char Date[20]; /* Date of current event. */
char msg[32]; /* Screen output buffer. */
int len; /* Used for string length. */
int x; /* Loop counter. */
int EventHandle; /* Event handle. */
if((EventHandle = CASGetCurrentEventStatus(Current)) == -NO_MORE_EVENTS)
fprintf (stdout,"No currently executing event.\n");
else {
CorrectDate((ECF *)Current, Date);
fprintf(stdout, "EVENT NUMBER : %d\n", EventHandle);
fprintf(stdout, "FROM : %s\n", Current->ControlFile.SenderName);
fprintf(stdout, "TO : %s\n\n", Current->ControlFile.DestinationName);
switch(Current->ControlFile.EventStatus) {
case COMPLETED : strcpy(msg, "Successfully completed"); break;
case WAITING : strcpy(msg, "Waiting to be processed"); break;
case DIALED : strcpy(msg, "Number has been dialed"); break;
case SENDING : strcpy(msg, "Connection made -- sending"); break;
case RECEIVING : strcpy(msg, "Connection made -- receiving"); break;
case ABORTED : strcpy(msg, "Event was aborted"); break;
default : {
strcpy(msg, "CCAM Error : ");
for(x = 1; x < UpperBound(CASEmsg); x++) {
if(CASEmsg[x].ExitCode == -Current->ControlFile.EventStatus) {
strcat(msg, CASEmsg[x].Message);
break;
}
}
}
}
fprintf(stdout, "EVENT STATUS : %s\n", msg);
fprintf(stdout, "ERRORS : %d\n", Current->ControlFile.ErrorCount);
switch(Current->ControlFile.EventType) {
case SEND : strcpy(msg, "Send"); break;
case RECEIVE : strcpy(msg, "Receive"); break;
case POLLED_SEND : strcpy(msg, "Polled Send"); break;
case POLLED_RECEIVE : strcpy(msg, "Polled Receive"); break;
default : strcpy(msg, "Error"); break;
}
fprintf(stdout, "EVENT TYPE : %s\n", msg);
switch(Current->ControlFile.TransferType) {
case FAX_200 : strcpy(msg, "200x200 Fax"); break;
case FAX_100 : strcpy(msg, "100x200 Fax"); break;
case FILE_TRANSFER : strcpy(msg, "File Transfer"); break;
default : strcpy(msg, " "); break;
}
fprintf(stdout, "TRANSFER TYPE : %s\n", msg);
switch(Current->ControlFile.EventStatus) {
case WAITING : fprintf(stdout, "DATE : Event in progress - board is waiting.\n"); break;
case DIALED : fprintf(stdout, "DATE : Event in progress - board is dialing.\n"); break;
case RECEIVING : fprintf(stdout, "DATE : Event in progress - board is receiving.\n"); break;
case ABORTED :
case COMPLETED :
case SENDING : fprintf(stdout, "DATE : %s\n", Date); break;
}
fprintf(stdout, "CONNECT TIME : %02d hr %02d min %02d sec\n",
(int)Current->ControlFile.ConnectHours,
(int)Current->ControlFile.ConnectMinutes,
(int)Current->ControlFile.ConnectSeconds);
fprintf(stdout, "NUMBER OF FILES : %d\n", Current->ControlFile.FileCount);
fprintf(stdout, "COVER PAGE : %s\n\n", Current->ControlFile.SendCover ? "Yes":"No");
fprintf(stdout, " FILE STATUS SIZE/PAGES NAME\n");
switch(Current->CurrentFileInTransit.FileStatus) {
case UNTOUCHED : strcpy(msg, "Untouched"); break;
case OPENED : strcpy(msg, "Opened"); break;
case MOVED : strcpy(msg, "Moved"); break;
case DELETED : strcpy(msg, "Deleted"); break;
case NOT_RECEIVED : strcpy(msg, "Not Received"); break;
}
fprintf(stdout, " %-15s", msg);
switch(Current->ControlFile.TransferType) {
case FAX_200 :
case FAX_100 : fprintf(stdout, " %6d", Current->CurrentFileInTransit.PageCount);
break;
case FILE_TRANSFER : fprintf(stdout, "%6ld ", Current->CurrentFileInTransit.FileSize);
break;
}
if((len = strlen(Current->CurrentFileInTransit.FileName)) > 40)
fprintf(stdout, " ...%-40s\n", Current->CurrentFileInTransit.FileName[80 - len]);
else
fprintf(stdout, " %-40s\n", Current->CurrentFileInTransit.FileName);
}
}
/*---------------------------------------------------------------------------*
* ShowState() *
*---------------------------------------------------------------------------*
* Show the state of the autoanswer feature. A return of 0 rings indicates *
* that the CCP hardware will not answer the phone line. *
*---------------------------------------------------------------------------*
* Parameters & Return: none *
*---------------------------------------------------------------------------*/
void ShowState()
{
int result; /* Function return value. */
int Rings; /* Number of rings before CCP answers phone. */
ShowAll = FALSE;
if((result = CASAutoReceiveState(GET, &(char)Rings)) == AR_ON)
fprintf(stdout, "Auto answer set to %d rings.\n", Rings);
else if (result == AR_OFF)
fprintf (stdout, "Auto answer is off.\n");
else
CASError(CASBADARS, FALSE, -result);
}
/*---------------------------------------------------------------------------*
* SetState() *
*---------------------------------------------------------------------------*
* Set the state of the autoanswer feature. Valid values are 0 <= n <= 255. *
* Trying to set the state to less than 0 results in setting the rings to 0. *
* Setting to greater than 255 results in setting to 255. *
*---------------------------------------------------------------------------*
* Parameters: int Rings - The number of rings before the CCP answers the *
* phone line. *
* Return: none *
*---------------------------------------------------------------------------*/
void SetState(int Rings)
{
int num; /* Number of rings to set autoanswer to. */
int result; /* Function call return value. */
ShowAll = FALSE;
/* Make sure that the number of rings is in acceptable range. */
if(Rings < 0)
num = 0;
else if(Rings > 255)
num = 255;
else
num = Rings;
/* Set auto answer state - possibly off if rings = 0. */
if((result = CASAutoReceiveState(SET, &(char)num)) == AR_ON)
fprintf(stdout, "Auto answer set to %d rings.\n", num);
else if (result == AR_OFF)
fprintf(stdout, "Auto answer turned off.\n");
else
CASError(CASBADARS, FALSE, -result);
}
/*---------------------------------------------------------------------------*
* Main *
*---------------------------------------------------------------------------*
* Display information about tasks in the Receive, Task and Log queues. First*
* get the needed buffers. Then display information according to the command *
* line switches. *
*---------------------------------------------------------------------------*
* Return: The DOS exit code is 0 if no errors are encountered, 1 for *
* commandline syntax errors, 2 for CCAM error, and 3 for DOS *
* errors. *
*---------------------------------------------------------------------------*/
main(int argc, char **argv)
{
int result; /* DOS & CAS function return value. */
argc = ParseCommand(argc, argv, SwitchTable, TABLESIZE);
/* Convert the event number to a long. */
EventNo = atol(JobNo);
/* If help is wanted, print info and exit (with 0 exit code). */
if(Help)
CASHelp(DescTable, DESCSIZE, HelpTable, HELPSIZE);
/* Insure that the Resident Scheduler is installed. */
if((result = CASGetInstalledState()) == INSTALLED) {
if(Diagnostics)
fprintf(stdout, " Resident scheduler installed.\n");
}
else {
if( result == NOTiOK )
CASError(CASNOHWO, TRUE, 0);
else
CASError(CASNOHWN, TRUE, 0);
}
/* Redirect stdout to a file. */
if(RedirOut) {
if((ccout = fopen("OUTPUT.CC", "w")) == NULL)
CASError(CASOPENTEMP, TRUE, 0);
if(-1 == dup2(fileno(ccout), 1))
CASError(CASBADREDIR, TRUE, 0);
}
/* Determine what information the user wants. */
if(!(TransmitOnly | LogOnly | NewOnly | CurrentEvent) && !(Diagnostics) && !(HardwareOnly) && (EventNo == 0))
ShowAll = TRUE;
/* Display and/or set the autoreceive state if requested. */
if(ARState) ShowState();
if(AnswerOnRing != -1) SetState(AnswerOnRing);
/* Get buffer for current event status information. */
TSTATbuffer = (CECS *)malloc(sizeof(CECS));
if(TSTATbuffer == NULL)
CASError(CASNOMEM, TRUE, 0);
/* Get buffer for Task information. */
TCFbuffer = (ECF *)malloc(sizeof(ECF));
if(TCFbuffer == NULL)
CASError(CASNOMEM, TRUE, 0);
/* Get buffer for File Transfer information. */
FTRbuffer = (FTR *)malloc(sizeof(FTR));
if(FTRbuffer == NULL)
CASError(CASNOMEM, TRUE, 0);
/* Get buffer for Extended data. */
EDBbuffer = (EDB *)malloc(sizeof(EDB));
if(EDBbuffer == NULL)
CASError(CASNOMEM, TRUE, 0);
/* If requested, run on-board diagnostics. Exit with error code if errors
are returned. */
if(Diagnostics)
RunDiagnostics();
/* If /C option selected, show current event status */
if (CurrentEvent)
ShowCurrentEvent(TSTATbuffer);
/* Show hardware status. */
if(HardwareOnly)
ShowHWStatus(TSTATbuffer, EDBbuffer);
/* Show Task Queue status. */
if((!NewOnly) && (TransmitOnly | ShowAll)) {
fprintf(stdout, "PENDING EVENTS : ");
ShowQueueStatus(ANY_STATUS, TASK_QUEUE, TCFbuffer, FTRbuffer);
}
/* Show Log Queue status. */
if(NewOnly | LogOnly | ShowAll) {
if(NewOnly)
fprintf(stdout, "NEW RECEIVE EVENTS : ");
else
fprintf(stdout, "COMPLETED EVENTS : ");
ShowQueueStatus(ANY_STATUS, LOG_QUEUE, TCFbuffer, FTRbuffer);
}
/* Show Event status. */
if(EventNo != 0) {
ShowJobStatus(EventNo, TCFbuffer, FTRbuffer, TSTATbuffer);
}
exit(0);
}